package cn.genmer.test.security.controller;

import cn.genmer.test.security.common.CommonResult;
import cn.genmer.test.security.utils.AliyunAddressUtils;
import cn.genmer.test.security.utils.AmapUtils;
import cn.genmer.test.security.utils.QmapUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/map")
@Api(tags = "地图服务Web服务控制器")
public class AmapController {

    /**
     * 高德正向地理编码接口
     */
    private static final String AMAP_GEO_URL = "http://restapi.amap.com/v3/geocode/geo?";
    /**
     * 高德POI搜索接口
     */
    private static final String AMAP_POI_URL = "https://restapi.amap.com/v3/place/text?";
    /**
     * 高德POI搜索接口
     */
    private static final String AMAP_IP_URL = "https://restapi.amap.com/v5/ip?";

    @ApiOperation("地址查询接口")
    @GetMapping("/amp/geo")
    public CommonResult location(@RequestParam String address){
       return AmapUtils.geo(address);
    }

    @ApiOperation("地址Poi查询接口")
    @GetMapping("/amp/poi")
    public CommonResult locationByPoi(@RequestParam String address){

        return AmapUtils.poi(address);
    }

    @ApiOperation("根据ip查询地址")
    @GetMapping("/amap/ip")
    public CommonResult locationByIP(@RequestParam String ip) {
        return AmapUtils.ip(ip);
    }


    @ApiOperation("腾讯地图分词接口")
    @GetMapping("/qmap")
    public CommonResult tencentAddressAnalysis(@RequestParam String address){

        return CommonResult.success(QmapUtils.addressAnalysis(address));
    }

    @ApiOperation("阿里云-地址标准化 地址补全")
    @GetMapping("/aliyun/complete")
    public CommonResult completeaddress(@RequestParam String address){
        return CommonResult.success(AliyunAddressUtils.completeAddress(address));
    }

    @ApiOperation("阿里云-地址标准化 地址结构化")
    @GetMapping("/aliyun/address/structure")
    public CommonResult structureaddress(@RequestParam String address){
        return CommonResult.success(AliyunAddressUtils.structureAddress(address));
    }

    @ApiOperation("阿里云-地址标准化 地址纠错")
    @GetMapping("/aliyun/address/correct")
    public CommonResult correctaddress(@RequestParam String address){
        return CommonResult.success(AliyunAddressUtils.correctAddress(address));
    }

    @ApiOperation("综合分析接口")
    @GetMapping()
    public CommonResult comprehensiveAnalysis(@RequestParam String address){
        HashMap<String, Object> map = new HashMap<>();

        String AResult = AliyunAddressUtils.completeAddress(address);
        String QResult = QmapUtils.addressAnalysis(address);

        map.put("AResult", CommonResult.stringSerializeObject(AResult));
        map.put("QResult", CommonResult.stringSerializeObject(QResult));
        return CommonResult.success(map);
    }

}
